<?php
use yii\helpers\Url;
use yii\helpers\Html;
//use app\modules\admin\assets\SweetalertAsset;
//
//SweetalertAsset::register($this);
$this->params['breadcrumbs'][] = '测试';
$this->title = "测试";
?>

<div class="row">
    <div class="col-sm-12">
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <?php foreach($cates as $cate): ?>
                    <li class="<?= $cate['id'] == $cate_id ? 'active' : '' ?>"><a href="<?= Url::to(['test', 'cate_id' => $cate['id']])?>"> <?= $cate['name'] ?></a></li>
                <?php endforeach; ?>
                <li class="pull-right">
                    <?= Html::a('<i class="fa fa-plus"></i> 创建', ['ajax-edit', 'cate_id' => $cate_id], [
                        'data-toggle' => 'modal',
                        'data-target' => '#ajaxModal',
                        'class' => 'btn btn-primary btn-xs',
                    ]); ?>
                </li>
            </ul>
            <div class="tab-content">
                <div class="active tab-pane">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th width="50">折叠</th>
                            <th>标题</th>
                            <th>路由</th>
                            <th>图标</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?= $this->render('tree', [
                            'models' => $models,
                            'parent_title' => '无',
                            'pid' => 0,
                            'cate_id' => $cate_id,
                        ]); ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
$deleteRoute = Url::to(['/admin/default/delete', 'id' => '']);
$js = <<<JS
//折叠
$('.cf').click(function(){
        var self = $(this);
        var id = self.parent().parent().attr('id');
        if(self.hasClass("fa-minus-square")){
            $('.'+id).hide();
            self.removeClass("fa-minus-square").addClass("fa-plus-square");
        } else {
            $('.'+id).show();
            self.removeClass("fa-plus-square").addClass("fa-minus-square");
            $('.'+id).find(".fa-plus-square").removeClass("fa-plus-square").addClass("fa-minus-square");
        }
    });
    $(document).ready(function() {
        $('.this-delete').click(function() {
            var key = $(this).data('key');
            // console.log(key);
            swal({
                title: "确定要删除吗？",
                text: "请确认以后再删除，删除以后将无法恢复",
                icon: "warning",
                buttons: ['取消', '确认'],
                dangerMode: true,
            }).then((willDetete) => {
                if (!willDetete) {
                return;
            }
            $.ajax({
                url: "$deleteRoute" + key,
                type: 'get',
                success: function (res) {
                    console.log(key);
                    location.reload();
                }
            });
        });
    });
});
JS;
$this->registerJs($js, \yii\web\View::POS_END);
$this->registerJsFile('adminL/dist/js/sweetalert.min.js', ['position' => \yii\web\View::POS_END]);
?>